<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"
prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"
prefix="fmt" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Insert title here</title>

<link href="../bootstrap/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
html {
	padding: 10px 20px 10px 20px;
}
</style>
</head>
<body>
	<div class="panel panel-default">
		<div class="panel-heading">文章修改</div>
		<div class="panel-body">
			<form class="form-horizontal" action="/ssm/edit_form/update" method="post" enctype="multipart/form-data">
			<input type="hidden" name="id" value="${post.id }">
			<!-- 上面的value="${post.id } ?表示后台传到这个界面来已经有post对象，post对象里面有id,title,content-->
				<div class="form-group">
					<label for="title" class="col-sm-2 control-label">文章标题</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" id="title" name="title" value="${post.title }">
					</div>
				</div>
				
				<div class="form-group">
					<label for="created" class="col-sm-2 control-label">创建时间</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" id="created" name="created" value='<fmt:formatDate value="${post.created }" pattern="yyyy-MM-dd"/>' >
					</div>
				</div>
				
				<div class="form-group">
					<label for="category" class="col-sm-2 control-label">文章分类</label>
					<div class="col-sm-2">
					<!-- 对应的name要和Post.java中要被封装的对象名字一致，比如Post中有Category对象 -->
						<select class="form-control" id="category" name="category.id">
						 <option value="-1" selected>请选中分类：</option>
							<c:forEach var="c" items="${categories }">
								<!-- 如果后台传来的post中的cid和category中的id相等,就将标签变为selected -->
								<c:choose>
									<c:when test="${c.id!=null&&c.id==post.category.id }">
										<option value="${c.id }" selected>${c.name }</option>
									</c:when>
									<c:otherwise>
										<option value="${c.id }">${c.name }</option>
									</c:otherwise>
								</c:choose>
							</c:forEach>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label for="content" class="col-sm-2 control-label">文章内容</label>
					<div class="col-sm-10">
						<textarea class="form-control" id="content" rows="4" name="content">${post.content }</textarea>
						<!-- textarea没有value值，不能接收后台post对象 -->
						
					</div>
				</div>
				<div class="form-group">
					<label for="postImage" class="col-sm-2 control-label">文章封面</label>
					<div class="col-sm-10">
					<!-- 文件上传的name就是传到后台，multipartFile接收的名字 -->
						<input type="file" name="upLoadFile" class="form-control-file" id="postImage">
					</div>
				</div>

				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-10">
						<button type="submit" class="btn btn-primary"
							style="width: 100px;">提交</button>
					</div>
				</div>
			</form>
		</div>
	</div>

	<script src="../js/jquery.min.js"></script>
	<script src="../bootstrap/bootstrap.min.js"></script>
</body>
</html>